<template>
  <div class="view_container">
    <el-table :data="tableData" border style="width: 100%" size="small">
      <el-table-column
        align="center"
        header-align="center"
        prop="id"
        label="编号"
        width="50"
      >
      </el-table-column>
      <el-table-column
        align="center"
        header-align="center"
        prop="name"
        label="资源名称"
      >
      </el-table-column>
      <el-table-column
        align="center"
        header-align="center"
        prop="url"
        label="资源路径"
      >
      </el-table-column>
      <el-table-column
        align="center"
        header-align="center"
        prop="description"
        label="描述"
      >
      </el-table-column>
      <el-table-column align="center" header-align="center" label="添加时间">
        <template slot-scope="scope">
          {{ formatDate(scope.row.createTime) }}
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="pag_content"
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { getResourceList } from "@/request/api";
import { formatDate } from "@/util/util";
export default {
  data() {
    return {
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 0,
    };
  },
  methods: {
    formatDate,
    handleSizeChange(size) {
      this.pageSize = size;
      this.fetchData();
    },
    handleCurrentChange(page) {
      this.currentPage = page;
      this.fetchData();
    },
    fetchData() {
      getResourceList({
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      }).then((res) => {
        if (res.code === 200) {
          this.tableData = res.data.list;
          this.total = res.data.total;
        }
      });
    },
  },
  created() {
    this.fetchData();
  },
};
</script>

<style lang="less" scoped>
.view_header_title {
  padding-left: 10px;
  font-size: 14px;
}
.inline_search {
  padding: 20px 40px 0;
}
.view_list {
  margin: 20px 0;
}
.fr {
  float: right;
}
.ml20 {
  margin-left: 20px;
}
.pag_content {
  float: right;
  margin: 20px 0;
}
.colorb {
  color: #666 !important;
}
</style>